package com.ruoyi.project.search.viewFactoryInOrOutJob.controller;

import java.util.List;

import com.ruoyi.project.search.viewFactoryInOrOutJob.domain.ViewFactoryInOrOutJob;
import com.ruoyi.project.search.viewFactoryInOrOutJob.service.IViewFactoryInOrOutJobService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工厂出入库Controller
 * 
 * @author qxq
 * @date 2024-04-23
 */
@Controller
@RequestMapping("/search/viewFactoryInOrOutJob")
public class ViewFactoryInOrOutJobController extends BaseController
{
    private String prefix = "search";

    @Autowired
    private IViewFactoryInOrOutJobService viewFactoryInOrOutJobService;

    @RequiresPermissions("viewFactoryInOrOutJob:viewFactoryInOrOutJob:view")
    @GetMapping()
    public String viewFactoryInOrOutJob()
    {
        return prefix + "/viewFactoryInOrOutJob";
    }

    /**
     * 查询工厂出入库列表
     */
    @RequiresPermissions("viewFactoryInOrOutJob:viewFactoryInOrOutJob:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ViewFactoryInOrOutJob viewFactoryInOrOutJob)
    {
//        startPage();
        List<ViewFactoryInOrOutJob> list = viewFactoryInOrOutJobService.selectViewFactoryInOrOutJobList(viewFactoryInOrOutJob);
        return getDataTable(list);
    }

    /**
     * 导出工厂出入库列表
     */
    @RequiresPermissions("viewFactoryInOrOutJob:viewFactoryInOrOutJob:export")
    @Log(title = "工厂出入库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ViewFactoryInOrOutJob viewFactoryInOrOutJob)
    {
        List<ViewFactoryInOrOutJob> list = viewFactoryInOrOutJobService.selectViewFactoryInOrOutJobList(viewFactoryInOrOutJob);
        ExcelUtil<ViewFactoryInOrOutJob> util = new ExcelUtil<ViewFactoryInOrOutJob>(ViewFactoryInOrOutJob.class);
        return util.exportExcel(list, "工厂出入库数据");
    }

    /**
     * 新增工厂出入库
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存工厂出入库
     */
    @RequiresPermissions("viewFactoryInOrOutJob:viewFactoryInOrOutJob:add")
    @Log(title = "工厂出入库", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ViewFactoryInOrOutJob viewFactoryInOrOutJob)
    {
        return toAjax(viewFactoryInOrOutJobService.insertViewFactoryInOrOutJob(viewFactoryInOrOutJob));
    }

    /**
     * 修改工厂出入库
     */
    @RequiresPermissions("viewFactoryInOrOutJob:viewFactoryInOrOutJob:edit")
    @GetMapping("/edit/{carNumber}")
    public String edit(@PathVariable("carNumber") String carNumber, ModelMap mmap)
    {
        ViewFactoryInOrOutJob viewFactoryInOrOutJob = viewFactoryInOrOutJobService.selectViewFactoryInOrOutJobByCarNumber(carNumber);
        mmap.put("viewFactoryInOrOutJob", viewFactoryInOrOutJob);
        return prefix + "/edit";
    }

    /**
     * 修改保存工厂出入库
     */
    @RequiresPermissions("viewFactoryInOrOutJob:viewFactoryInOrOutJob:edit")
    @Log(title = "工厂出入库", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ViewFactoryInOrOutJob viewFactoryInOrOutJob)
    {
        return toAjax(viewFactoryInOrOutJobService.updateViewFactoryInOrOutJob(viewFactoryInOrOutJob));
    }

    /**
     * 删除工厂出入库
     */
    @RequiresPermissions("viewFactoryInOrOutJob:viewFactoryInOrOutJob:remove")
    @Log(title = "工厂出入库", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(viewFactoryInOrOutJobService.deleteViewFactoryInOrOutJobByCarNumbers(ids));
    }
}
